import { transformParams } from '@/utils/utils';
import { ProTableProps } from '@ant-design/pro-components';
import ProTable from '@ant-design/pro-table';
import type { FC } from 'react';
export interface Params {
  page: number; //pageIndex
  per_page: number; //pageSize
  [key: string]: any;
}
interface TableProps extends ProTableProps<any, any> {
  getDataSource?: (params: Params) => Promise<any>;
  rowSelection?: any;
}
const NormalTable: FC<TableProps> = (props) => {
  const { getDataSource } = props;
  return (
    <ProTable
      rowSelection={props.rowSelection || {}}
      search={{ defaultCollapsed: false }}
      pagination={{ defaultPageSize: 20 }}
      bordered
      size="large"
      scroll={{ x: 'max-content' }}
      request={
        getDataSource ? (params, sort) => getDataSource(transformParams(params, sort)) : undefined
      }
      {...props}
    />
  );
};

export default NormalTable;
